<?php
/**
 * Feed
 * 
 * @version $Id$
 */

class Module_feed
{
	/**
	 * 构造函数
	 */
	function __construct() {
		
	}

	/**
	 * 默认 action
	 */
	function index() {
		$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
		$type = isset($_GET['type']) ? trim($_GET['type']) : 'friend';
		
		if($page < 1) {
			$page = 1;
		}
		
		loadLib('Feed');
		
		$smarty = loadSmarty();
		$uin = SessionInfo('uin');
		
		// 需要获取的用户数据
		$uins_arr = array($uin);
		$per_page = 10;
		
		if($type == 'all') {
			$feeds = Feed::getAllList( ($page - 1) * $per_page , $per_page + 1 );		// 多取一条，为了判断是否有更多feed
		} else {
			// 获取自己所有好友
			loadLib('Friend');
			$friends_arr = Friend::get($uin);
			
			// 获取feed ，获取自己+好友的feed
			$get_feeds_uins = $friends_arr;
			$get_feeds_uins[] = $uin;
			$feeds = Feed::getList( $get_feeds_uins , ($page - 1) * $per_page , $per_page + 1 );		// 多取一条，为了判断是否有更多feed
		}
		
		
		foreach($feeds as $k => $feed) {
			$feeds[$k]['data'] = unserialize($feed['data']);
			
			$uins_arr[] = $feed['uin'];
		}
		
		// 处理用户数据
		loadLib('User');
		$uins_info = User::getBaseInfo($uins_arr);
		
		function feedFormatContent($feed) {
			return Feed::formatContent($feed);
		}
		// $smarty->registerPlugin('modifier' , 'feedFormatContent' , 'Feed::formatContent');
		$smarty->assign('feeds' , $feeds);
		$smarty->assign('uins_info' , $uins_info);
		$smarty->assign('cur_page' , $page);
		$smarty->assign('per_page' , $per_page);
		$smarty->assign('type' , $type);

		return $smarty->fetch('feed/index.tpl.php');
	}
}

# end of script
